/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tigris.jasmincc.framework.implementation;

import org.tigris.jasmincc.Production;
import org.tigris.jasmincc.framework.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Get the production by keyword.
 * 
 * @author Sam Huang
 * 
 */
public class SimpleProductionFactory implements ProductionFactory {

	protected Production defaultProduction = null;

	protected Log logger = LogFactory.getLog(getClass());

	/**
	 * @param defaultProduction
	 *            the defaultProduction to set
	 */
	public void setDefaultProduction(Production defaultProduction) {
		this.defaultProduction = defaultProduction;
	}

	public Production getProduction(String name) {
		Production production;

		try {
			// if (name.equals("<")) {
			// return (Production) SimpleObjectFactory.getInstance()
			// .getBeanFactory().getBean("regexRegionProduction");
			// }
			production = (Production) SimpleObjectFactory.getInstance()
					.getBeanFactory().getBean(name);
		} catch (Exception ex) {
			// messenger.println("default production is used");
			// logger.info("default production is used" + ex.toString());
			return defaultProduction;
		}
		return production;
	}

}
